package com.cqc.other.juc.producerConsumer.blockingQueue.demo1;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;

public class Container {

    /**
     * 初始化阻塞队列
     */
//    private final BlockingQueue<Integer> queue = new ArrayBlockingQueue<>(10);
    private final BlockingQueue<Integer> queue = new PriorityBlockingQueue<>();

    /**
     * 添加数据到阻塞队列
     * @param value
     */
    public void add(Integer value) {
        try {
            queue.put(value);
            System.out.println("生产者："+ Thread.currentThread().getName()+"，add：" + value);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * 从阻塞队列获取数据
     */
    public void get() {
        try {
            Integer value = queue.take();
            System.out.println("消费者："+ Thread.currentThread().getName()+"，value：" + value);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}